﻿using AnyCAD.Foundation;
using AnyCAD.NX.ViewModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace AnyCAD.Primitive.Domain
{
    internal partial class DomainViewModel : ComponentViewModel
    {

        DomainModel Model { get => (DomainModel)_Model; }
        public DomainViewModel(Element entity, GeneralComponent component, MainViewModel mainViewModel)
            : base(new DomainModel(), entity, component, mainViewModel) 
        {
            Length = Model.MaxPt.x;
            Width = Model.MaxPt.y;
            Height = Model.MaxPt.z;
        }

        public override bool IsApplyVisible => false;

        [ObservableProperty]
        double _Width = 100;
        partial void OnWidthChanged(double value)
        {
            UpdateModel();
        }

        [ObservableProperty]
        double _Height = 100;
        partial void OnHeightChanged(double value)
        {
            UpdateModel();
        }

        [ObservableProperty]
        double _Length = 100;
        partial void OnLengthChanged(double value)
        {
            UpdateModel();
        }

        void UpdateModel()
        {
            SetProperty(nameof(DomainModel.MaxPt), ref Model.MaxPt, new GPnt(Length, Width, Height));           
        }
    }
}
